using System;
using System.Collections.Generic;

namespace DanielSig
{
	public class SortedLinkedList<T> : LinkedList<T>
	{
		public void Add(T item)
		{
			if(Count == 0) base.AddFirst(item);
			else
			{
				int hash = item.GetHashCode();
				LinkedListNode<T> link = this.First;
				while(link != null)
				{
					if(hash < link.Value.GetHashCode())
					{
						base.AddBefore(link, item);
						break;
					}
					else if(item.Equals(link.Value))
					{
						throw new ArgumentException("item " + item.ToString() + "must be unique");
					}
					link = link.Next;
				}
				if(link == null)
					base.AddLast(item);
			}
		}
		public new LinkedListNode<T> AddLast(T item)
		{
			throw new InvalidOperationException("AddLast() can not be used. Please use Add() instead");
		}
		public new void AddLast(LinkedListNode<T> item)
		{
			throw new InvalidOperationException("AddLast() can not be used. Please use Add() instead");
		}
		public new LinkedListNode<T> AddFirst(T item)
		{
			throw new InvalidOperationException("AddFirst() can not be used. Please use Add() instead");
		}
		public new void AddFirst(LinkedListNode<T> item)
		{
			throw new InvalidOperationException("AddFirst() can not be used. Please use Add() instead");
		}
		
		public new LinkedListNode<T> AddAfter(LinkedListNode<T> node, T value)
		{
			throw new InvalidOperationException("AddAfter() can not be used. Please use Add() instead");
		}
		public new void AddAfter(LinkedListNode<T> node, LinkedListNode<T> newNode)
		{
			throw new InvalidOperationException("AddAfter() can not be used. Please use Add() instead");
		}
		public new LinkedListNode<T> AddBefore(LinkedListNode<T> node, T value)
		{
			throw new InvalidOperationException("AddBefore() can not be used. Please use Add() instead");
		}
		public new void AddBefore(LinkedListNode<T> node, LinkedListNode<T> newNode)
		{
			throw new InvalidOperationException("AddBefore() can not be used. Please use Add() instead");
		}
	}
}